package designpattern.proxy;

import designpattern.proxy.api.DemoManager;
import designpattern.proxy.impl.DemoManagerCustom;
import designpattern.proxy.impl.DemoManagerImpl;

/**
 * @Author Antony
 * @Since 2018/6/20 15:47
 */
public class ProxyMain {

    public static void main(String[] args) {
        //executeJDKProxyTest();
        executeCGlibProxyTest();
    }


    private static void executeJDKProxyTest(){
        DemoManager jdkDemo = (DemoManager) ProxyFactory.createJDKProxyInstance(new DemoManagerImpl(), "number1");
        DemoManager jdkDemo_02 = (DemoManager) ProxyFactory.createJDKProxyInstance(new DemoManagerCustom());
        jdkDemo.add(1,"Antony");
        jdkDemo.delete(2);
        jdkDemo_02.add(1,"Antony");
        jdkDemo_02.delete(2);
    }

    private static void executeCGlibProxyTest(){
        DemoManager cgDemo = (DemoManager) ProxyFactory.createCGlibProxyInstance(new DemoManagerImpl(), "homura");
        DemoManager cgDemo_02 = (DemoManager) ProxyFactory.createCGlibProxyInstance(new DemoManagerCustom());
        cgDemo.add(1,"Antony");
        cgDemo.delete(2);
        cgDemo_02.add(1,"Antony");
        cgDemo_02.delete(2);
    }
}
